// Package api
// @Author: zhangdi
// @File: sys_generation
// @Version: 1.0.0
// @Date: 2023/8/31 14:08
package sysctrl

import (
	"server/application/auto/gen"
	"server/application/dto"
	"server/pkg/ginp"
)

func SysGenEntityNames(ctx *ginp.ContextPro) {
	list := gen.GetEntityNames()
	ctx.OkJsonData(list)
}

func SysGenEntityInfo(ctx *ginp.ContextPro) {
	var params *dto.ReqEntityInfo
	if err := ctx.ShouldBindJSON(&params); err != nil {
		ctx.ErrJson("请求参数有误" + err.Error())
		return
	}
	entityInfo, err := gen.GetEntityInfoByFile(params.EntityName)
	if err != nil {
		ctx.ErrJson("请求有误" + err.Error())
		return
	}
	ctx.OkJsonData(entityInfo)
}

func SysGenEntitySave(ctx *ginp.ContextPro) {
	var params *gen.EntityInfo
	if err := ctx.ShouldBindJSON(&params); err != nil {
		ctx.ErrJson("请求参数有误" + err.Error())
		return
	}
	gen.SaveEntityInfoToFile(params)
	ctx.OkJson()
}

func SysGenFile(ctx *ginp.ContextPro) {
	go gen.InitGenTableInfo()
	ctx.OkJson()
}
